package com.bizfx.component.fields
{
	import com.bizfx.component.controls.CheckBoxTree;
	import com.bizfx.component.views.IDetailView;
	import com.bizfx.utils.StringUtils;

	import mx.collections.ArrayCollection;
	import mx.collections.IList;
	import mx.utils.UIDUtil;
	
	public class CheckBoxTreeField extends CheckBoxTree implements IField, IInitableField
	{
		public function CheckBoxTreeField()
		{
			super();
			this.setStyle("disabledOverlayAlpha", 0);
			this.setStyle("disabledColor", 0x000000);
		}
		
		[Bindable]
		public function get fieldKey():String
		{
			return this.id;
		}
		
		public function set fieldKey(value:String):void
		{
			this.id = value;
		}
		
		private var _bindProperty:String;
		[Bindable]
		public function get bindProperty():String
		{
			return _bindProperty;
		}
		
		public function set bindProperty(value:String):void
		{
			this._bindProperty = value;
		}
		
//		private var _view:IDetailView;
//		
//		public function get view():IDetailView
//		{
//			return this._view;
//		}
//		
//		public function set view(value:IDetailView):void {
//			if (StringUtils.isNullOrEmpty(this.id)) {
//				this.id = UIDUtil.createUID();
//			}
//			if (this._view !== value) {
//				if (_view) {
//					_view.removeFieldByKey(this.fieldKey);
//				}
//				this._view = value;
//				if (_view) {
//					_view.addField(this);
//				}
//			}
//		}
		
		[Bindable]
		override public function get data():Object {
			return this.checkedItems;
		}
		
		override public function set data(value:Object):void {
			if (value is ArrayCollection) {
				this.checkedItems = value as ArrayCollection;
			}
		}
		
		private var _initDataBindProperty:String;
		[Bindable]
		public function get initDataBindProperty():String
		{
			return _initDataBindProperty;
		}

		public function set initDataBindProperty(value:String):void {
			_initDataBindProperty = value;
		}
		
		private var _needInit:Boolean = false;
		[Bindable]
		public function get needInit():Boolean
		{
			return _needInit;
		}
		
		public function set needInit(value:Boolean):void {
			_needInit = value;
		}

		[Inspectable(category="General", enumeration="true,false", defaultValue="false")]
		[Bindable("readOnlyChanged")]
		public function get readOnly():Boolean {
			return this.enabled;
		}
		
		public function set readOnly(value:Boolean):void {
			if (this.enabled == value) {
				this.enabled = !value;
				this.dispatchEvent(new Event("readOnlyChanged"));
			}
		}
	}
}